﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Runtime.InteropServices;

namespace ScpServer
{
    public partial class Overlay : Form
    {

        private const int SW_SHOWNOACTIVATE = 4;
        private const int HWND_TOPMOST = -1;
        private const uint SWP_NOACTIVATE = 0x0010;

        [DllImport("user32.dll", EntryPoint = "SetWindowPos")]
        static extern bool SetWindowPos(
             int hWnd,             // Window handle
             int hWndInsertAfter,  // Placement-order handle
             int X,                // Horizontal position
             int Y,                // Vertical position
             int cx,               // Width
             int cy,               // Height
             uint uFlags);         // Window positioning flags

        [DllImport("user32.dll")]
        static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

        public Overlay()
        {
            InitializeComponent();
            int x = (Screen.PrimaryScreen.WorkingArea.Width - this.Width)/2;
            int y = Screen.PrimaryScreen.WorkingArea.Height - this.Height;
            this.Location = new Point(x, y);
        }

        private void Overlay_Shown(object sender, EventArgs e)
        {
            SetOverlay();
            //MessageBox.Show("hi");
        }
        private void SetOverlay()
        {
            ShowWindow(this.Handle, SW_SHOWNOACTIVATE);
            SetWindowPos(this.Handle.ToInt32(), HWND_TOPMOST,
            this.Left, this.Top, this.Width, this.Height,
            SWP_NOACTIVATE);
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (this.Visible)
                this.Hide();
            else
                this.Show();
                SetOverlay();
        }

     
    }
}
